#!/usr/bin/python2.6
#coding: utf8

import sys
import string

TAG_POS = 1<<24
TAG_GRAM = 2<<24
TAG_NR = 3<<24
TAG_NS = 4<<24
TAG_TR = 5<<24
TAG_UNKNOWN = 6<<24

hash_nr = {
			'A':0,
			'B':1,
			'C':2,
			'D':3,
			'E':4,
			'F':5,
			'G':6,
			'L':7,
			'M':8,
			'N':9,
			'X':10,
			'Y':11,
			'Z':12,
			'*':13,
		};

hash_ns = {
			'A':0,
			'B':1,
			'C':2,
			'D':3,
			'L':4,
			'M':5,
			'N':6,
			'*':7,
		};

hash_tr = {
			'A':0,
			'B':1,
			'C':2,
			'D':3,
			'L':4,
			'M':5,
			'N':6,
			'*':7,
		};

if len(sys.argv) != 2 :
	sys.exit(1)

if sys.argv[1] == '-r' :
	hash = hash_nr
	tagk = TAG_NR
elif sys.argv[1] == '-s' :
	hash = hash_ns
	tagk = TAG_NS
elif sys.argv[1] == '-t' :
	hash = hash_tr
	tagk = TAG_TR
else :
	print >> sys.stderr, '-r , -s or -t'
	sys.exit(2)

print >> sys.stderr, 'ne...'

i = 0
for line in sys.stdin:
	i += 1
	arr = line.split()
	if(len(arr) != 3):
		print >> sys.stderr, 'error line[', i, ']: ', line
		continue
	word = arr[0]
	pos  = arr[1]
	freq = arr[2]
	if not hash.has_key(pos) :
		print >> sys.stderr, 'pos line[', i, ']: ', line
		continue
	posn = hash[pos] + tagk
	print word,'\t',posn,'\t',freq
